//    Copyright (C) Kherty.  All rights reserved.
using OpenLS.Core.Serialization;

namespace OpenLS.Drawing
{
    internal class TableStyleCellStyle : IOfficeXmlSerializable
    {
        internal const string xmlName = "tcStyle";
        private Cell3D _cell3D;
        private TableCellBorderStyle _tcBdr;
        private StyleMatrixReference fillRef;
        private FillProperties fill;

        #region IOfficeXmlSerializable Members

        public void ReadXml(ReadContext context)
        {
            using (var c = context.Read(xmlName))
            {
                _tcBdr = c.ReadOptionalElement<TableCellBorderStyle>("tcBdr");
                this.fill = FillProperties.ReadFillProperties(c);
                if (this.fill == null)
                    fillRef = c.ReadElementAs<StyleMatrixReference>("fillRef");
                _cell3D = c.ReadOptionalElement<Cell3D>("cell3D");
            }
        }

        public void WriteXml(WriteContext context)
        {
            using (var c = context.Write(xmlName))
            {
                c.WriteOptionalElement(_tcBdr);
                c.WriteOptionalElement(fill);
                c.WriteOptionalElementAs(fillRef, "fillRef");
                c.WriteOptionalElement(_cell3D);
            }
        }

        #endregion
    }
}